package com.ticket.controller;

import com.ticket.entity.Collect;
import com.ticket.entity.Comment;
import com.ticket.service.CollectService;
import com.ticket.service.CommentService;
import com.ticket.service.impl.CollectServiceImpl;
import com.ticket.service.impl.CommentServiceImpl;
import com.ticket.util.Page;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 全谢民
 * @version 8.0
 * @description: TODO   用户评论控制器
 * @date 2023/10/15 21:32
 */
public class UserCommentController {
    CommentService cs = new CommentServiceImpl();

    /**
     * @param request
     * @param response
     * @return java.lang.Object
     * @author 全谢民
     * @description TODO    用户评论
     * @date 2023/10/15 21:32
     */
    public Object userCommentAll(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        Page<Comment> page = new Page(4, 1);
        String pageIndex = request.getParameter("index");
        if (pageIndex != null && pageIndex != "") {
            page.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        //获取值
        int userId = Integer.parseInt(request.getParameter("userId"));
        String activityType = request.getParameter("activityType");
        session.setAttribute("activityType", activityType);
        Comment comment = new Comment(userId, activityType);
        page = cs.selCommentList(comment, page);
        request.setAttribute("page", page);
        return "forward:/user_page/userComments.jsp";
    }

    /**
     * @param request
     * @param response
     * @return java.lang.Object
     * @author 全谢民
     * @description TODO    用户删除个人评论
     * @date 2023/10/16 14:26
     */
    public Object userDelComment(HttpServletRequest request, HttpServletResponse response) {
        int commentId = Integer.parseInt(request.getParameter("commentId"));
        int count = cs.delComment(commentId);
        return count;
    }
}
